"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var api_1 = require("../../../config/api");
var NewsListComponent = /** @class */ (function () {
    function NewsListComponent(httpService, router, route) {
        this.httpService = httpService;
        this.router = router;
        this.route = route;
        this.aliyunOssOutputUrl = api_1.AliyunOssOutputUrl;
        this.categoryID = 0; // 资讯类型
        this.itemsPerPage = 12;
        this.categoryName = '所有资讯';
        this.classifyList = []; // 所有分类
    }
    NewsListComponent.prototype.ngOnInit = function () {
        var _this = this;
        this.route.queryParams.subscribe(function (res) {
            _this.categoryID = +res.categoryId || 0;
        });
        this.getClassifyList();
        this.getAllArtical(1, this.itemsPerPage, this.categoryID);
    };
    // 获取所有最新资讯列表
    NewsListComponent.prototype.getAllArtical = function (page, pageSize, categoryID) {
        var _this = this;
        var url;
        if (!!categoryID && categoryID != 0) {
            url = api_1.adSystemApiUrl + "/v1/fddata/posts/list?page=" + page + "&pageSize=" + pageSize + "&categoryID=" + categoryID;
        }
        else {
            url = api_1.adSystemApiUrl + "/v1/fddata/posts/list?page=" + page + "&pageSize=" + pageSize;
        }
        return this.httpService.httpGetAuth(url)
            .subscribe(function (data) {
            _this.currentPage = data.data.current_page;
            _this.totalItems = data.data.total;
            _this.allInfo = data.data.data;
        });
    };
    // 获取分类列表
    NewsListComponent.prototype.getClassifyList = function () {
        var _this = this;
        var url = api_1.adSystemApiUrl + "/v1/fddata/category/list";
        return this.httpService.httpGetAuth(url)
            .subscribe(function (data) {
            _this.classifyList = data.data;
        });
    };
    NewsListComponent.prototype.changeType = function (data) {
        this.categoryID = data.id;
        this.categoryName = data.name;
        this.getAllArtical(1, this.itemsPerPage, this.categoryID);
    };
    // 跳转到新闻详情页
    NewsListComponent.prototype.turnNewsDetail = function (data) {
        this.router.navigate(['/home/news-detail/' + data.id], { queryParams: { categoryId: data.category_id } });
    };
    NewsListComponent.prototype.pageChanged = function (event) {
        window.scrollTo(0, 0);
        this.getAllArtical(event.page, event.itemsPerPage, this.categoryID);
    };
    NewsListComponent = __decorate([
        core_1.Component({
            selector: 'app-news-list',
            templateUrl: 'news-list.component.html',
            styleUrls: ['news-list.component.scss']
        })
    ], NewsListComponent);
    return NewsListComponent;
}());
exports.NewsListComponent = NewsListComponent;
